export default defineNuxtRouteMiddleware(async (to, from) => {
  const token = useCookie("Authorization");
  // 已登录，强制重定向到首页
  if (import.meta.client && token.value) {
    // 客户端渲染
    try {
      const res = await $fetch("/api/signs/beats");
      const user = res?.data;
      if (!user)
        return;

      const userStore = useMyUserStore();
      userStore.setUser(user);
      useToast().add({
        title: "您已登录",
        description: "即将跳转到首页",
        callback: () => navigateTo("/"),
        timeout: 1500,
      });
    }
    catch (e: any) {
      if (isNuxtError(e))
        console.log("visitor error", JSON.stringify(e));

      // return navigateTo("/login");
    }
  }
});
